<!DOCTYPE html>
<html lang="en">
	<head>
		<title>three.js webgl - materials</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
		<link type="text/css" rel="stylesheet" href="main.css">
	</head>
	<body>
		<div id="info">
			<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - webgl materials
		</div>

		<script type="module">

			import * as THREE from '../build/three.module.js';

			import Stats from './jsm/libs/stats.module.js';

			let stats;

			let camera, scene, renderer;
			let pointLight;

			const objects = [], materials = [];

			init();
			animate();

			function init() {

				const container = document.createElement( 'div' );
				document.body.appendChild( container );

				camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );
				camera.position.set( 0, 200, 800 );

				scene = new THREE.Scene();

				// Grid

				let helper = new THREE.GridHelper( 1000, 40, 0x303030, 0x303030 );	
				helper.position.y = - 75;	
				scene.add( helper );			
				

				// Spheres geometry

				let geometry = new THREE.SphereBufferGeometry( 70, 32, 16 );
				let material = new THREE.MeshLambertMaterial( { color: 0xdddddd } ) ;
				let mesh = new THREE.Mesh( geometry, material );
				
				scene.add( mesh );

				// Lights

				scene.add( new THREE.AmbientLight( 0x111111 ) );

				const directionalLight = new THREE.DirectionalLight( 0xffffff, 0.125);

				directionalLight.position.x = -0.04;
				directionalLight.position.y = 0.22;
				directionalLight.position.z = 0.13;
				
				directionalLight.position.normalize();


				scene.add( directionalLight );		

				pointLight = new THREE.PointLight( 0xffffff, 1 );
				pointLight.position.x = 0.0;
				pointLight.position.y = 200.0;
				pointLight.position.z = 800.0;				
				scene.add( pointLight );				

				//

				renderer = new THREE.WebGLRenderer( { antialias: true } );
				renderer.setPixelRatio( window.devicePixelRatio );
				renderer.setSize( window.innerWidth, window.innerHeight );
				container.appendChild( renderer.domElement );

				//

				stats = new Stats();
				container.appendChild( stats.dom );

				//

				window.addEventListener( 'resize', onWindowResize, false );

			}
			

			function onWindowResize() {

				camera.aspect = window.innerWidth / window.innerHeight;
				camera.updateProjectionMatrix();

				renderer.setSize( window.innerWidth, window.innerHeight );

			}

			
			//

			function animate() {

				requestAnimationFrame( animate );

				render();
				stats.update();

			}

			function render() {

				const timer = 0.0001 * Date.now();


				camera.lookAt( scene.position );	
				

				renderer.render( scene, camera );

			}

		</script>

	</body>
</html>
